import { Body, Controller, Get, Post } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { ArticleService } from './article.service';
import { Article } from './article.interface';
import { CreateArticleDTO } from './article.dto';

interface ArticleResponse<T = unknown> {
  code: number;
  data?: T;
  message: string;
}

@ApiTags('文章接口')
@Controller('article')
export class ArticleController {
  constructor(private readonly articeService: ArticleService) {}

  @Get('getArticleAll')
  async findAll(): Promise<ArticleResponse<Article[]>> {
    return {
      code: 200,
      data: await this.articeService.finAll(),
      message: '成功',
    };
  }

  @Post('addArticle')
  async addOne(@Body() body: CreateArticleDTO): Promise<ArticleResponse> {
    await this.articeService.addOne(body);
    return {
      code: 200,
      message: '成功',
    };
  }
}
